package com.wzxy.pf.sys.controller;

import com.wzxy.pf.sys.dto.SysDTO;
import com.wzxy.pf.sys.entity.User;
import com.wzxy.pf.sys.service.SysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/system")
public class SysController {
@Autowired
    private SysService sysService;


  /*
    修改个人信息
     */
@PostMapping("/updateUserMessage")
    public String updateUserMessageById(@RequestBody User user){

    user.setUpdateTime(LocalDateTime.now());
    user.setCreateTime(LocalDateTime.now());
    boolean result = this.sysService.updateUsermessage(user);
    if(result){
        return "success";
    }else{
        return "fail";
    }
}
  /*
  修改密码
     */
@PostMapping("/updatePassword")
public String updatePasswordById(@RequestBody User user) {
    String a = sysService.findPasswordById(user);
    System.out.println(a);
    System.out.println(user);
    if (a.equals(user.getOldpassword())) {
        user.setUpdateTime(LocalDateTime.now());
        user.setCreateTime(LocalDateTime.now());
        boolean result = this.sysService.updatePassword(user);
    }else {
        return "fail";
    }
    return "success";
}
}
